package name.jiaosha.air.company.controller;

import java.util.List;

import name.jiaosha.air.OperateTip;
import name.jiaosha.air.company.domain.CarInfo;
import name.jiaosha.air.company.domain.Company;
import name.jiaosha.air.company.service.ICompanyService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller("carInfoController")
public class CarInfoController {

	@Autowired
	private ICompanyService companyService;

	public List<CarInfo> getMyCarInfoList() {

		List<CarInfo> list = companyService.getCarListByComId(null);

		return list;
	}

	public OperateTip create(CarInfo carInfo) {

		Company company = companyService.getCompanyById(1);
		carInfo.setCompany(company);
		companyService.createCarInfo(carInfo);

		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}

	public OperateTip update(CarInfo carInfo) {

		CarInfo car = companyService.getCarInfoById(carInfo.getId());
		car.setCarCode(carInfo.getCarCode());
		car.setName(carInfo.getName());

		companyService.updateCarInfo(car);
		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}

	public CarInfo getCarInfoById(int id) {

		return companyService.getCarInfoById(id);
	}

}
